package com.sc.highspeed.controller;

import com.sc.highspeed.controller.result.JsonResult;
import com.sc.highspeed.db.model.*;
import com.sc.highspeed.service.*;


import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.sc.highspeed.constant.Constant.pageSize;

/**
 * Created by Admin on 2017/11/27.
 */
@Api(value = "车辆信息管理接口", description = "车辆信息管理接口")
@Controller
@RequestMapping("/carManage")
public class CarManagerController {

    @Autowired
    private CarInfoService carInfoService;

    @Autowired
    private EsCarInfoService esCarInfoService;

    @Autowired
    private CarInfoTempService carInfoTempService;

    @Autowired
    private EsCarInfoTempService esCarInfoTempService;

    @Autowired
    private UserService userService;

    private static final Logger check = Logger.getLogger("check");

    /**
     * 获取车辆信息
     * @param number
     * @param color
     * @return
     */
    @RequestMapping(value = "/getCarInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据车牌号和颜色获取车辆详细信息",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getCarInfoByNumber(@ApiParam(value = "车牌号") @RequestParam String number, @ApiParam(value = "车牌颜色") @RequestParam String color) {
        JsonResult result = new JsonResult();
        CarInfoModel carInfoModel = carInfoService.getCarInfoByNumber(number, color);
        if (carInfoModel != null) {
            result.setCode(1);
            result.setStatus(true);
            result.setObject(carInfoModel);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("该车辆信息不存在！");
        }

        return result;
    }

    /**
     * 获取全部车辆信息
     * @return
     */
    @RequestMapping(value = "/getCarInfoList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取所有车辆基本信息列表（已经审核通过）",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getCarInfoList(@ApiParam(value = "页码") @RequestParam(defaultValue = "1") int pageNow) {
        JsonResult result = new JsonResult();
        List list = new ArrayList();
        int startRow = pageSize * (pageNow - 1);
        List<CarInfoModel> carInfoModels = carInfoService.getCarInfoList(startRow, pageSize);
        list.add(carInfoService.getCarInfoNumber());
        list.add(carInfoModels);
        result.setObject(list);
        return result;
    }

    @RequestMapping(value = "/getCarInfoListUnCheck", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取所有未通过审核的车辆基本信息列表",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getCarInfoListUnCheck(@ApiParam(value = "页码") @RequestParam(defaultValue = "1") int pageNow) {
        JsonResult result = new JsonResult();
        List list = new ArrayList();
        int startRow = pageSize * (pageNow - 1);
        List<CarInfoModel> carInfoModels = carInfoTempService.getCarInfoList(startRow, pageSize);
        list.add(carInfoTempService.getCarInfoNumber());
        list.add(carInfoModels);
        result.setObject(list);
        return result;
    }

    @RequestMapping(value = "/updateCarInfoCheck", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "对待审核车辆基本信息进行通过操作",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult updateCarInfoCheck(@ApiParam(value = "id") @RequestParam int id, @ApiParam(value = "操作用户名") @RequestParam String username) {
        JsonResult result = new JsonResult();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String checkTime = dateFormat.format(date);
        UserModel userModel = userService.getUserByUsername(username);
        String name = userModel.getName();
        String organization = userModel.getOrganization();
        CarInfoModel temp = carInfoTempService.getCarInfoById(id);
        String status = temp.getStatus();
        int code = 0;

        if (status.equals("添加")) {
            if (carInfoService.getCarInfoByNumber(temp.getNumber(), temp.getColor()) == null || temp.getColor().equals("")) {
                temp.setReviewer(name);
                temp.setAudit(organization);
                temp.setAuditTime(checkTime);
                code = carInfoService.insertCarInfo(temp);
                if (code == 1) {
                    result.setCode(1);
                    result.setStatus(true);
                    carInfoTempService.deleteCarInfoById(id);
                } else {
                    result.setCode(0);
                    result.setStatus(false);
                    result.setMsg("添加失败！");
                }
            } else {
                result.setCode(-1);
                result.setStatus(false);
                result.setMsg("该车辆信息已存在！");
                carInfoTempService.deleteCarInfoById(id);
            }
        } else if (status.equals("删除")) {
            int carId = carInfoService.getCarInfoByNumber(temp.getNumber(), temp.getColor()).getId();
            code = carInfoService.deleteCarInfoById(carId);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
                carInfoTempService.deleteCarInfoById(id);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("删除失败！");
            }
        } else if (status.equals("更新")) {
            int carId = temp.getCarId();
            temp.setId(carId);
            code = carInfoService.updateCarInfoById(temp);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
                carInfoTempService.deleteCarInfoById(id);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("更新失败！");
            }
        }
        check.info(username + "对该条记录审核通过" + temp);
        return result;
    }

    @RequestMapping(value = "/updateCarInfoNotCheck", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "对待审核车辆基本信息进行未通过操作",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult updateCarInfoNotCheck(@ApiParam(value = "id") @RequestParam int id, @ApiParam(value = "操作用户名") @RequestParam(required = false) String username) {
        JsonResult result = new JsonResult();
        CarInfoModel carInfoModel = carInfoTempService.getCarInfoById(id);
        String status = carInfoModel.getStatus();
        int code = carInfoTempService.deleteCarInfoById(carInfoModel.getId());
        if (code == 1) {
            result.setCode(1);
            result.setStatus(true);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("操作失败！");
        }
        if (username != null) {
            check.info(username + "对该条记录审核通过" + carInfoModel);
        }

        return result;
    }

//    /**
//     * 删除车辆信息
//     * @param id
//     * @return
//     */
//    @RequestMapping("/deleteCarInfo")
//    @ResponseBody
//    public JsonResult deleteCarInfoById(@RequestParam int id) {
//        JsonResult result = new JsonResult();
//        CarInfoModel carInfoModel = carInfoService.getCarInfoById(id);
//        carInfoModel.setStatus("删除");
//        int code = carInfoTempService.insertCarInfo(carInfoModel);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("提交失败！");
//        }
//        return result;
//    }

    @RequestMapping(value = "/deleteCarInfos", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "批量删除车辆基本信息",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public List<JsonResult> deleteCarInfosById(@ApiParam(value = "id数组(ids)") @RequestBody Map<String, Object> map) {
        List<JsonResult> results = new ArrayList<JsonResult>();
        List<Integer> ids = (ArrayList<Integer>) map.get("ids");
        CarInfoModel carInfoModel = null;
        int code = 0;
        for (int id : ids) {
            JsonResult result = new JsonResult();
            carInfoModel = carInfoService.getCarInfoById(id);
            if (carInfoTempService.getCarInfoByNumber(carInfoModel.getNumber(), carInfoModel.getColor()) != null) {
                result.setCode(-1);
                result.setStatus(false);
                result.setMsg("已存在对该车辆的审核操作,请等待审核完毕！");
                results.add(result);
                continue;
            }
            carInfoModel.setStatus("删除");
            code = carInfoTempService.insertCarInfo(carInfoModel);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("提交失败！");
            }

            results.add(result);
        }
        return results;
    }

    /**
     * 更新车辆信息
     * @param carInfoModel
     * @return
     */
    @RequestMapping(value = "/updateCarInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "更新车辆基本信息",httpMethod = "POST",
            response = JsonResult.class, notes = "车辆基本信息实体")
    public JsonResult updateCarInfoById(@RequestBody CarInfoModel carInfoModel) {
        JsonResult result = new JsonResult();
        if (carInfoTempService.getCarInfoByNumber(carInfoModel.getNumber(), carInfoModel.getColor()) != null) {
            result.setCode(-1);
            result.setStatus(false);
            result.setMsg("已存在对该车辆的审核操作,请等待审核完毕！");
            return result;
        }
        carInfoModel.setStatus("更新");
        carInfoModel.setCarId(carInfoModel.getId());
        int code = carInfoTempService.insertCarInfo(carInfoModel);
        if (code == 1) {
            result.setCode(1);
            result.setStatus(true);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("提交失败！");
        }
        return result;
    }

    /**
     * 添加车辆信息
     * @param carInfoModel
     * @return
     */
    @RequestMapping(value = "/insertCarInfo",consumes = "application/json", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加车辆信息",httpMethod = "POST",
            response = JsonResult.class, notes = "")
    public JsonResult insertCarInfo(@ApiParam(value = "车辆基本信息实体") @RequestBody CarInfoModel carInfoModel) {
        JsonResult result = new JsonResult();
        if (carInfoTempService.getCarInfoByNumber(carInfoModel.getNumber(), carInfoModel.getColor()) == null || carInfoModel.getColor().equals("")) {
            carInfoModel.setStatus("添加");
            int code = carInfoTempService.insertCarInfo(carInfoModel);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("提交失败！");
            }
        } else {
            result.setCode(-1);
            result.setStatus(false);
            result.setMsg("该车辆信息已提交！");
        }

        return result;
    }

//    @RequestMapping(value = "/updateCarInfoRemark", method = RequestMethod.GET)
//    @ResponseBody
//
//    public JsonResult updateCarInfoRemarkByNumber(@RequestParam int id, @RequestParam String remark) {
//        JsonResult result = new JsonResult();
//        int code = carInfoService.updateCarInfoRemarkById(id, remark);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("更新失败！");
//        }
//        return result;
//    }

    /**
     * 获取车辆逃费信息
     * @param number
     * @param color
     * @return
     */
    @RequestMapping(value = "/getEsCarInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "通过车牌号和颜色获取车辆逃费信息",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getEsCarInfoByNumber(@ApiParam(value = "车牌号") @RequestParam String number, @ApiParam(value = "颜色") @RequestParam String color) {
        JsonResult result = new JsonResult();
        List<EsCarInfoModel> esCarInfoModel = esCarInfoService.getEsCarInfoByNumber(number, color);
        if (esCarInfoModel != null) {
            result.setCode(1);
            result.setStatus(true);
            result.setObject(esCarInfoModel);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("该车辆逃费信息不存在！");
        }
        return result;
    }

    @RequestMapping(value = "/searchEsCarInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "车辆逃费信息搜索",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult searchEsCarInfo(@ApiParam(value = "开始时间") @RequestParam(required = false) String startTime,@ApiParam(value = "结束时间") @RequestParam(required = false) String endTime,
                                      @ApiParam(value = "逃费类型") @RequestParam(required = false) String type, @ApiParam("黑灰白名单") @RequestParam(required = false) String list,
                                      @ApiParam(value = "车牌颜色")@RequestParam String color, @ApiParam(value = "车牌号") @RequestParam String number, HttpServletRequest request) {
        JsonResult result = new JsonResult();
        int minRmb = 0, maxRmb = 0;
        String minRmbStr = request.getParameter("minRmb");
        String maxRmbStr = request.getParameter("maxRmb");
        if (minRmbStr != null && maxRmbStr != null) {
            if (!minRmbStr.equals("") && !maxRmbStr.equals("")) {
                minRmb = Integer.valueOf(minRmbStr);
                maxRmb = Integer.valueOf(maxRmbStr);
            }
        }
        List<EsCarInfoModel> esCarList = esCarInfoService.searchEsCarInfo(startTime, endTime, type, list, minRmb, maxRmb, color, number);

        if (esCarList != null) {
            result.setCode(1);
            result.setStatus(true);
            result.setObject(esCarList);
        } else {
            result.setCode(-1);
            result.setStatus(false);
            result.setMsg("搜索结果不存在！");
        }
        return result;
    }

    @RequestMapping(value = "/getSingleEsCarInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取单条逃费车辆信息",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getSingleEsCarInfoById(@ApiParam(value = "id") @RequestParam int id) {
        JsonResult result = new JsonResult();
        EsCarInfoModel esCarInfoModel = esCarInfoService.getEsCarInfo(id);
        if (esCarInfoModel != null) {
            result.setCode(1);
            result.setStatus(true);
            result.setObject(esCarInfoModel);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("该车辆逃费信息不存在！");
        }
         return result;
    }

    @RequestMapping(value = "/getEsCarInfoListUnCheck", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取未审核逃费车辆信息列表",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getEsCarInfoListUnCheck(@ApiParam(value = "页码") @RequestParam(defaultValue = "1") int pageNow) {
        JsonResult result = new JsonResult();
        int startRow = pageSize * (pageNow - 1);
        List list = new ArrayList();
        list.add(esCarInfoTempService.getEsCarInfoNumber());
        List<EsCarInfoTempModel> esCarInfoTempModels = esCarInfoTempService.getEsCarInfoList(startRow, pageSize);
        list.add(esCarInfoTempModels);
        result.setObject(list);
        return result;
    }


    @RequestMapping(value = "/updateEsCarInfoCheck", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "对未审核车辆逃费信息进行通过操作",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult updateEsCarInfoCheck(@ApiParam(value = "id") @RequestParam int id, @ApiParam(value = "用户名") @RequestParam String username) {
        JsonResult result = new JsonResult();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String checkTime = dateFormat.format(date);
        UserModel userModel = userService.getUserByUsername(username);
        String name = userModel.getName();
        String organization = userModel.getOrganization();
        EsCarInfoModel esCarInfoModel = esCarInfoTempService.getEsCarInfoById(id);
        String status = esCarInfoModel.getStatus();
        int code = 0;

        if (status.equals("添加")) {
            esCarInfoModel.setReviewer(name);
            esCarInfoModel.setAudit(organization);
            esCarInfoModel.setAuditTime(checkTime);
            code = esCarInfoService.insertEsCarInfo(esCarInfoModel);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
                esCarInfoTempService.deleteEsCarInfoById(id);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("操作失败！");
            }
        } else if (status.equals("更新")) {
            esCarInfoModel.setId(esCarInfoModel.getEsId());
            code = esCarInfoService.updateEsCarInfoById(esCarInfoModel);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
                esCarInfoTempService.deleteEsCarInfoById(id);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("操作失败！");
            }
        } else if (status.equals("删除")) {
            int esCarId = esCarInfoTempService.getEsCarInfoById(id).getEsId();
            code = esCarInfoService.deleteEsCarInfoById(esCarId);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
                esCarInfoTempService.deleteEsCarInfoById(id);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("操作失败！");
            }
        }
        check.info(username + "对该条记录审核通过：" + esCarInfoModel);
        return result;
    }

    @RequestMapping(value = "/updateEsCarInfoNotCheck", method = RequestMethod.GET)
        @ResponseBody
    @ApiOperation(value = "对未审核车辆逃费信息进行未通过操作",httpMethod = "GET",
            response = JsonResult.class, notes = "")
        public JsonResult updateEsCarInfoNotCheck(@ApiParam(value = "id") @RequestParam int id, @ApiParam(value = "用户名") @RequestParam String username) {
            JsonResult result = new JsonResult();
            EsCarInfoModel esCarInfoModel = esCarInfoTempService.getEsCarInfoById(id);
            String status = esCarInfoModel.getStatus();
            int code = esCarInfoTempService.deleteEsCarInfoById(id);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("操作失败！");
            }
            if (username != null) {
                check.info(username + "对该条记录审核未通过：" + esCarInfoModel.getNumber() + "；" + esCarInfoModel.getColor());
            }
            return result;
    }
    /**
     * 获取所有车辆逃费信息
     * @return
     */
    @RequestMapping(value = "/getEsCarInfoList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取车辆逃费信息列表（已通过审核）",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getEsCarInfoList(@ApiParam(value = "页码")@RequestParam int pageNow) {
        JsonResult result = new JsonResult();
        List list = new ArrayList();
        int startRow = pageSize * (pageNow - 1);
        List<EsCarInfoModel> esCarInfoModels = esCarInfoService.getEsCarInfoList(startRow, pageSize);
        list.add(esCarInfoService.getEsCarInfoNumber());
        list.add(esCarInfoModels);
        result.setObject(list);
        return result;
    }

    /**
     * 添加车辆逃费信息
     * @param esCarInfoModel
     * @return
     */
    @RequestMapping(value = "/insertEsCarInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加车辆逃费信息",httpMethod = "POST",
            response = JsonResult.class, notes = "")
    public JsonResult insertEsCarInfo(@ApiParam(value = "车辆逃费信息实体") @RequestBody EsCarInfoModel esCarInfoModel) {
        JsonResult result = new JsonResult();
//        if (!esCarInfoTempService.getEsCarInfoByNumber(esCarInfoModel.getNumber(), esCarInfoModel.getColor()).isEmpty()) {
//            result.setCode(-1);
//            result.setStatus(false);
//            result.setMsg("该车辆逃费信息已提交！");
//            return result;
//        }
        esCarInfoModel.setStatus("添加");
        int code = esCarInfoTempService.insertEsCarInfo(esCarInfoModel);
        if (code == 1) {
            result.setCode(1);
            result.setStatus(true);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("提交失败！");
        }

        return result;
    }

//    /**
//     * 删除车辆逃费信息
//     * @param esCarInfoTempModel
//     * @return
//     */
//    @RequestMapping("/deleteEsCarInfo")
//    @ResponseBody
//    public JsonResult deleteEsCarInfoById(@RequestBody EsCarInfoTempModel esCarInfoTempModel) {
//        JsonResult result = new JsonResult();
//        esCarInfoTempModel.setStatus("删除");
//        esCarInfoTempModel.setEsId(esCarInfoTempModel.getId());
//        int code = esCarInfoTempService.insertEsCarInfo(esCarInfoTempModel);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("提交失败！");
//        }
//        return result;
//    }

    @RequestMapping(value = "/deleteEsCarInfos", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "批量删除车辆逃费信息",httpMethod = "POST",
            response = JsonResult.class, notes = "")
    public List<JsonResult> deleteEsCarInfosById(@ApiParam(value = "id数组(ids)") @RequestBody Map<String, Object> map) {
        List<JsonResult> results = new ArrayList<JsonResult>();
        List<Integer> ids = (ArrayList<Integer>) map.get("ids");
        EsCarInfoModel esCarInfoModel = null;
        int code = 0;
        for (int id : ids) {
            JsonResult result = new JsonResult();
            esCarInfoModel = esCarInfoService.getEsCarInfo(id);
            if (esCarInfoTempService.getEsCarInfoByEsId(esCarInfoModel.getId()) != null) {
                result.setCode(-1);
                result.setStatus(false);
                result.setMsg("已存在对该车辆的审核操作,请等待审核完毕！");
                results.add(result);
                continue;
            }
            esCarInfoModel.setEsId(esCarInfoModel.getId());
            esCarInfoModel.setStatus("删除");
            code = esCarInfoTempService.insertEsCarInfo(esCarInfoModel);
            if (code == 1) {
                result.setCode(1);
                result.setStatus(true);
            } else {
                result.setCode(0);
                result.setStatus(false);
                result.setMsg("提交失败！");
            }

            results.add(result);
        }
        return results;
    }

    /**
     * 更新车辆逃费信息
     * @param esCarInfoModel
     * @return
     */
    @RequestMapping(value = "/updateEsCarInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "更新车辆逃费信息",httpMethod = "POST",
            response = JsonResult.class, notes = "")
    public JsonResult updateEsCarInfoById(@ApiParam(value = "车辆逃费信息实体") @RequestBody EsCarInfoModel esCarInfoModel) {
        JsonResult result = new JsonResult();
        if (esCarInfoTempService.getEsCarInfoByEsId(esCarInfoModel.getId()) != null) {
            result.setCode(-1);
            result.setStatus(false);
            result.setMsg("已存在对该车辆的审核操作,请等待审核完毕！");
            return result;
        }
        esCarInfoModel.setStatus("更新");
        esCarInfoModel.setEsId(esCarInfoModel.getId());
        int code = esCarInfoTempService.insertEsCarInfo(esCarInfoModel);
        if (code == 1) {
            result.setCode(1);
            result.setStatus(true);
        } else {
            result.setCode(0);
            result.setStatus(false);
            result.setMsg("提交失败！");
        }
        return result;
    }

//    /**
//     * 更新车辆逃费是否拉入名单
//     * @param id
//     * @param isList
//     * @return
//     */
//    @RequestMapping(value = "/updateEsCarInfoIsList", method = RequestMethod.GET)
//    @ResponseBody
//    public JsonResult updateEsCarInfoIsListById(@RequestParam int id, @RequestParam String isList) {
//        JsonResult result = new JsonResult();
//        int code = esCarInfoService.updateEsCarInfoIsListById(id,isList);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("修改失败！");
//        }
//
//        return result;
//    }
//
//    /**
//     * 更新车辆逃费信息所在名单
//     * @param id
//     * @param list
//     * @return
//     */
//    @RequestMapping(value = "/updateEsCarInfoList", method = RequestMethod.GET)
//    @ResponseBody
//    public JsonResult updateEsCarInfoListById(@RequestParam int id, @RequestParam String list) {
//        JsonResult result = new JsonResult();
//        int code = esCarInfoService.updateEsCarInfoListById(id, list);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("修改失败！");
//        }
//        return result;
//    }
//
//    @RequestMapping("/updateEsCarInfoIsProcessById")
//    @ResponseBody
//    public JsonResult updateEsCarInfoIsProcessById(@RequestParam int id, @RequestParam String isProcess) {
//        JsonResult result = new JsonResult();
//        int code = esCarInfoService.updateEsCarInfoIsProcessById(id, isProcess);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("更新失败！");
//        }
//        return result;
//    }
//
//    @RequestMapping("/updateEsCarInfoProcessById")
//    @ResponseBody
//    public JsonResult updateEsCarInfoProcessById(@RequestParam int id, @RequestParam String process) {
//        JsonResult result = new JsonResult();
//        int code = esCarInfoService.updateEsCarInfoProcessById(id, process);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("更新失败！");
//        }
//        return result;
//    }
//
//    @RequestMapping("/updateEsCarInfoRemarkById")
//    @ResponseBody
//    public JsonResult updateEsCarInfoRemarkById(@RequestParam int id, @RequestParam String remark) {
//        JsonResult result = new JsonResult();
//        int code = esCarInfoService.updateEsCarInfoRemarkById(id, remark);
//        if (code == 1) {
//            result.setCode(1);
//            result.setStatus(true);
//        } else {
//            result.setCode(0);
//            result.setStatus(false);
//            result.setMsg("更新失败！");
//        }
//        return result;
//    }

    @RequestMapping(value = "/getHistory", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取个人提交审核列表",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getEsCarInfoListByUsername(@ApiParam(value = "用户名") @RequestParam String creatorUsername) {
        JsonResult result = new JsonResult();
        List<CarInfoModel> carInfoModels = carInfoTempService.getCarInfoListByUsername(creatorUsername);
        List<EsCarInfoTempModel> esCarInfoTempModels = esCarInfoTempService.getEsCarInfoListByUsername(creatorUsername);
        List list = new ArrayList();
        list.add(carInfoModels);
        list.add(esCarInfoTempModels);
        result.setObject(list);
        return result;
    }

    @RequestMapping(value = "/getHazy", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "搜索",httpMethod = "GET",
            response = JsonResult.class, notes = "")
    public JsonResult getHazyInfo(@ApiParam(value = "车牌号") @RequestParam String number, @ApiParam(value = "车牌颜色") @RequestParam String color,
                                  @ApiParam(value = "查询类别(carInfo(车辆基本信息),esCarInfo(车辆逃费信息),carInfoTemp(待审核车辆基本信息),esCarInfoTemp(待审核车辆逃费信息))") @RequestParam String type) {
        JsonResult result = new JsonResult();
        result.setCode(1);
        result.setStatus(true);
        if (type.equals("carInfo")) {
            result.setObject(carInfoService.getHazyCarInfo(number, color));
        } else if (type.equals("esCarInfo")) {
            result.setObject(esCarInfoService.getHazyEsCarInfo(number, color));
        } else if (type.equals("carInfoTemp")) {
            result.setObject(carInfoTempService.getHazyCarInfo(number, color));
        } else if (type.equals("esCarInfoTemp")) {
            result.setObject(esCarInfoTempService.getHazyEsCarInfo(number, color));
        }
        return result;
    }

}
